package org.example.mall.admin.model.entity.goods;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.example.mall.admin.constant.vaild.C;
import org.example.mall.admin.constant.vaild.Q;
import org.example.mall.admin.constant.vaild.U;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * <p>
 * 规格模板值
 * </p>
 *
 * @author hzq
 * @since 2022-01-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("spec_params")
@ApiModel(value = "SpecParams对象", description = "规格模板值")
public class SpecParams extends Model<SpecParams> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "主键")
    @TableId(value = "id", type = IdType.AUTO)
    @NotNull(message = "id不能为空", groups = U.class)
    private Integer id;

    @NotBlank(message = "属性名称不能为空", groups = {C.class, U.class})
    @ApiModelProperty(value = "属性名称")
    @TableField("label")
    private String label;

    @NotNull(message = "搜索字段不能为空", groups = C.class)
    @ApiModelProperty(value = "是否作为搜索字段，将来在搜索页面使用，boolean类型")
    @TableField("search_able")
    private Boolean searchAble;

    @NotNull(message = "全局属性字段不能为空", groups = C.class)
    @ApiModelProperty(value = "是否是SPU全局属性，boolean类型。true为全局属性，false为SKU的特有属性")
    @TableField("global")
    private Boolean global;

    /**
     * JSON 数组字符串
     */
    @ApiModelProperty(value = "属性值的可选项，数组结构。起约束作用，不允许填写可选项以外的值，比如CPU核数，有人添10000核岂不是很扯淡")
    @TableField("options")
    private String options;

    @NotNull(message = "数值属性字段不能为空", groups = C.class)
    @ApiModelProperty(value = "是否为数值，boolean类型，true则为数值，false则不是。为空也代表非数值")
    @TableField("numerical")
    private Boolean numerical;

    @ApiModelProperty(value = "单位，如：克，毫米。如果是数值类型，那么就需要有单位，否则可以不填。")
    @TableField("unit")
    private String unit;

    @NotNull(message = "分组id不能为空", groups = {C.class, Q.class})
    @ApiModelProperty(value = "分组id（sys_label.id）")
    @TableField("group_id")
    private Integer groupId;

    @ApiModelProperty(value = "排序")
    @TableField("sort")
    private Integer sort;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }

}
